import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/internal/Observable';
import { map } from 'rxjs/operators';

import { ApiService, JsonResult } from './api.service';
import { PageVo, ProgramListVo } from 'src/app/shared/models';

@Injectable({
  providedIn: 'root'
})
export class ProgramService {

  constructor(
    private apiservice: ApiService
  ) { }

  /**
   * 获取项目列表
   * @param pageIndex 页码
   * @param pageSize 每页显示几条信息
   */
  getProgramPage(pageIndex: number, pageSize: number): Observable<PageVo<ProgramListVo>> {
    const params = new HttpParams()
      .append('pageIndex', `${pageIndex}`)
      .append('pageSize', `${pageSize}`);
    return this.apiservice.get('/project/list', { params })
      .pipe(
        map((jsonResult: JsonResult<PageVo<ProgramListVo>>) => jsonResult.data)
      );
  }

}
